package iscript.coreFramework.data.pager 
{
	/**
	 * ...
	 * @author raymond
	 */
	public class BasePager 
	{
		
		public function BasePager(length:int) 
		{
			_recordCount = length;
		}
		
		private var _recordCount:int;
		public  function get  recordCount():int {
			return _recordCount;
			}
		
		
		/**
		 * 一页几条数据
		 */
		private  var _pageSize:int = 5;
		
		public function get pageSize():int {
			return _pageSize;
			}
			
		public function set pageSize(value:int):void {
			 _pageSize=value;
			}
		
			
		private var _currentPageIndex:int = 1;
		/**
		 * 当前页
		 */
		public function get currentPageIndex():int {
			return _currentPageIndex;
			}
			
		/**
		 * 设置当前页
		 */	
		public function set currentPageIndex(value:int):void {
			 _currentPageIndex=autoCurrentPageIndex(value);
			}
			
		private function autoCurrentPageIndex(pageindex:int):int {
			var pageindex:int = pageindex;
			if (pageindex < 1) {pageindex = 1;}
			if (pageindex > pageCount) {pageindex = pageCount;}
			    _currentPageIndex = pageindex;
				return _currentPageIndex;
			}	
			
			
		public  function get pageCount():int {
			   var pageCount:int = 0;			   
			   if (recordCount % pageSize == 0) {
				   pageCount = recordCount/pageSize
				   }else {
				   pageCount = recordCount/pageSize+1
				}
			    return  pageCount;
			}
			
			
		public  function getNumberByPageIndex(pageIndex:int):Array {
				if (pageIndex > pageCount) {pageIndex = pageCount;}
				if (pageIndex <1) {pageIndex = 1;}
				var len:int = pageIndex == pageCount? recordCount - pageSize * (pageIndex - 1):pageSize;
				var data:Array = new Array();
				for (var i:int = (pageIndex-1)*pageSize; i <(pageIndex-1)*pageSize+len; i++) 
						{
							data.push(i);
						}					
				return data;
				}	
			
		public 	 function  getNumberByCurrentPage():Array {
				return getNumberByPageIndex(_currentPageIndex);
		     }
	}

}